package com.deshan.websys.code.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.deshan.websys.code.mapper.PmsKeyWordMapper;
import com.deshan.websys.code.model.PmsKeyWord;
import com.deshan.websys.code.model.UmsRose;
import com.deshan.websys.code.service.PmsKeyWordService;
import com.deshan.websys.code.utils.BeanUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PmsKeyWordServiceImpl implements PmsKeyWordService {
    @Resource
    PmsKeyWordMapper pmsKeyWordMapper;
    @Override
    public int saveorupdate(PmsKeyWord pmsKeyWord) {

        Integer id=pmsKeyWord.getId();
        int result=0;
        if(id==null){
            result=  pmsKeyWordMapper.insert(pmsKeyWord);
        }else{
            PmsKeyWord descKeyWord=pmsKeyWordMapper.selectById(id);
            try{
                BeanUtil.copyNotNullProperties(descKeyWord,pmsKeyWord);
                result=  pmsKeyWordMapper.updateById(descKeyWord);
            }catch (Exception ex){

            }

        }
        return  result;
    }

    @Override
    public int delete(Integer id) {
        int result=0;
        try{
            result=   pmsKeyWordMapper.deleteById(id);
        }catch (Exception ex){

        }

        return result;
    }

    @Override
    public List<PmsKeyWord> findKeyWord(String keyword) {
        QueryWrapper<PmsKeyWord> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("keyword", keyword);
        List<PmsKeyWord> listrose=pmsKeyWordMapper.selectList(queryWrapper);
        return listrose;
    }

    @Override
    public List<PmsKeyWord> getKeyWords() {
        QueryWrapper<PmsKeyWord> queryWrapper =new QueryWrapper<>();

        List<PmsKeyWord> listrose=pmsKeyWordMapper.selectList(queryWrapper);
        return listrose;
    }
}
